<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>用videojs测试浏览器兼容性</title>
  
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/eruda/1.5.4/eruda.min.js"></script>
<script>
eruda.init();
</script>

</head>
<body>

<audio id="myAudio" class="video-js vjs-default-skin"></audio>

<div style="padding:20px 0 200px">
<div>国外的玩意，除了好看就是容易误操作，上面如果是空白，代表：加载很慢↑↑↑↑ （也有可能是他们更新了页面，但这个测试html还未及时同步更新）</div>
<div>显示出录音界面后，点击大麦克风按钮打开录音，再点击左下角圆点按钮开始录音，再点按钮结束录音，录完后点左下角的播放箭头播放</div>

<div style="padding:20px 0">原始测试地址：<a href="https://collab-project.github.io/videojs-record/demo/audio-only.html">https://collab-project.github.io/videojs-record/demo/audio-only.html</a></div>

<hr>

<div>
【测试方法】：使用上面的录音功能进行测试看看能否正常录音。

<br><br>
【附带测试】：
<br>


<div><audio class="recPlay" style="width:100%"></audio></div>


音乐播放测试：
<button onclick="recplay2(this,'rec-4000ms-8kbps-16000hz.wav')">wav</button>
<button onclick="recplay2(this,'rec-4000ms-64kbps-16000hz.mp3')">mp3</button>
<button onclick="recplay2(this,'rec-4000ms-64kbps-16000hz.ogg')">ogg</button>
<button onclick="recplay2(this,'rec-4000ms-64kbps-16000hz.webm')">webm</button>
<button onclick="recplay2(this,'rec-4000ms-12.8kbps-8000hz.amr')">amr</button>

Audio对录音的影响测试（<a href="https://github.com/xiangyuecn/Recorder/issues/34">issues#34</a>）；IOS Safari如果未开始过录音并且播放了音乐，然后后续录音将会有问题；再现方法(<a href="ztest_apple_developer_forums_getusermedia.html">test apple developer forums</a>)：刷新页面后首先先播放音乐，然后开始测试录音，会发现波形显示掉帧或者保持直线。另测试浏览器对音频的支持情况。
</div>

<script>
var recblob={};
function recplay(key){
	var audio=$(".recPlay")[0];
	audio.controls=true;
	if(!(audio.ended || audio.paused)){
		audio.pause();
	};
	
	var o=recblob[key];
	if(o){
		o.play=(o.play||0)+1;
		var logmsg=function(msg){
			$(".p"+key).html('<span style="color:green">'+o.play+'</span> '+new Date().toLocaleTimeString()+" "+msg);
		};
		logmsg("");
		audio.onerror=function(e){
			console.log(arguments)
			logmsg('<span style="color:red">播放失败</span>');
		};
		
		if(o.play2Name){
			audio.src="audio/"+o.play2Name;
			audio.play();
			return;
		};
	};
};
function recplay2(elem,name){
	elem=$(elem);
	var key="recplay2"+elem.html();
	recblob[key]||(recblob[key]={
		play2Name:name
	});
	if(!$(".p"+key).length){
		elem.before('<br>');
		elem.after('<span class="p'+key+'"></span><br>');
	};
	
	recplay(key);
};
</script>


</div>

















<!--------照抄页面源码，改改url地址，他这个页面在gh-pages分支，jsdelivr地址要找一下对应的master里的文件--------->
 
<link href="https://unpkg.com/video.js@7.14.3/dist/video-js.min.css" rel="stylesheet">
<link href="https://unpkg.com/videojs-wavesurfer/dist/css/videojs.wavesurfer.min.css" rel="stylesheet">
<link href="https://unpkg.com/videojs-record/dist/css/videojs.record.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/gh/collab-project/videojs-record@latest/examples/assets/css/examples.css" rel="stylesheet">

<script src="https://unpkg.com/video.js@7.14.3/dist/video.min.js"></script>
<script src="https://unpkg.com/recordrtc/RecordRTC.js"></script>
<script src="https://unpkg.com/webrtc-adapter/out/adapter.js"></script>
<script src="https://unpkg.com/wavesurfer.js/dist/wavesurfer.min.js"></script>
<script src="https://unpkg.com/wavesurfer.js/dist/plugin/wavesurfer.microphone.min.js"></script>
<script src="https://unpkg.com/videojs-wavesurfer/dist/videojs.wavesurfer.min.js"></script>

<script src="https://unpkg.com/videojs-record/dist/videojs.record.min.js"></script>

<script src="https://cdn.jsdelivr.net/gh/collab-project/videojs-record@latest/examples/browser-workarounds.js"></script>


<style>
/* change player background color */
#myAudio {
    background-color: #9FD6BA;
}
</style>

<script>
var options = {
    controls: true,
    bigPlayButton: false,
    width: 600,
    height: 300,
    plugins: {
        wavesurfer: {
            backend: 'WebAudio',
            waveColor: '#36393b',
            progressColor: 'black',
            displayMilliseconds: true,
            debug: true,
            cursorWidth: 1,
            hideScrollbar: true,
            plugins: [
                // enable microphone plugin
                WaveSurfer.microphone.create({
                    bufferSize: 4096,
                    numberOfInputChannels: 1,
                    numberOfOutputChannels: 1,
                    constraints: {
                        video: false,
                        audio: true
                    }
                })
            ]
        },
        record: {
            audio: true,
            video: false,
            maxLength: 20,
            displayMilliseconds: true,
            debug: true
        }
    }
};

// apply some workarounds for certain browsers
applyAudioWorkaround();

// create player
var player = videojs('myAudio', options, function() {
    // print version information at startup
    var msg = 'Using video.js ' + videojs.VERSION +
        ' with videojs-record ' + videojs.getPluginVersion('record') +
        ', videojs-wavesurfer ' + videojs.getPluginVersion('wavesurfer') +
        ', wavesurfer.js ' + WaveSurfer.VERSION + ' and recordrtc ' +
        RecordRTC.version;
    videojs.log(msg);
});

// error handling
player.on('deviceError', function() {
    console.log('device error:', player.deviceErrorCode);
});

player.on('error', function(element, error) {
    console.error(error);
});

// user clicked the record button and started recording
player.on('startRecord', function() {
    console.log('started recording!');
});

// user completed recording and stream is available
player.on('finishRecord', function() {
    // the blob object contains the recorded data that
    // can be downloaded by the user, stored on server etc.
    console.log('finished recording: ', player.recordedData);
});
</script>

</body>
</html>
